#pragma once
#ifndef xTimer_H__
#define xTimer_H__
#include "../../dxhead/dxegheader.h"
#include "skyType.h"
namespace Sky
{
class TimeCounter
{
private:
	//QueryPerformanceFrequency() API can be used or not
	static TBool m_bUsingQPF;
	//Ticks per second
	static TUint64 m_llQPFTickesPerSec;


	//time len between GetTicksCounted() and Reset() called excluded m_llUncountedLen
	TUint64 m_llCountedLen;
	//the sum of time len between Stop() and Start() called
	TUint64 m_llUncountedLen;
	//time len between GetTimeElapsed() and GetTimeElapsed() called
	TUint64 m_llElapsedLen;


	//time when GetTimeElapsed called
	TUint64 m_llLastElapsedTime;	//relative to system time
	//time when Stop() called
	TUint64 m_llLastStoppedTime;   //relative to system time
	//time when Reset() called
	TUint64 m_llLastResetedTime;   //relative to system time

public:
	DXAPI static TUint64 GetTicksPerSecond();
	//
	DXAPI TimeCounter();
	//reset all counters, after Reset, Start should be called to launch the timer
	//*ResetTime: out, the time of time reseted in abslute style
	DXAPI TVoid Reset(TUint64* ResetTime = vNull);
	//contuine to count
	//*StartTime: out, the time of timer started in abslute style
	DXAPI TVoid Start(TUint64* StartTime = vNull);
	//stop to count but keep counters unchanged
	//*StopTime:out, the time of timer stopped in abslute style
	DXAPI TVoid Stop(TUint64* StopTime = vNull);

	//update Timer and return the time from last reset time to now 
	//not including stoped period<---->timecounted
	DXAPI TUint64 CalTicksCounted();
	//update Timer and return the time from last CalTicksElapsed() to now 
	//not including stoped period<---->timecounted
	DXAPI TUint64 CalTicksElapsed();

	//return the time from last CalTicksElapsed() to now 
	//not including stoped period<---->timecounted
	DXAPI TUint64 GetTicksElapsed();
	//return the time from last reset time to now 
	//not including stoped period<---->timecounted
	DXAPI TUint64 GetTicksCounted();
	//Timer stopped
	DXAPI TBool   IsStopped();
};
}
#endif // xTimer_H__
